<?php
require_once('../../pers/inc.config.php');
if (file_exists(RGL_FS_WEB_ROOT.'/stop.txt')) {
	header("location: ".RGL_URL_ROOT."/app/_com/stop.php");
	exit();
}
require_once(RGL_FS_WEB_ROOT."/app/_inc/inc.set1.php");
require_once(RGL_FS_WEB_ROOT."/app/_inc/class.rglSession.php");

if (!isset($isPopUp)) $isPopUp = false;
if (!isset($isReloadable)) $isReloadable = false;
if(phpversion() < 5){
	die("PHP 5 or greater is needed.");
}

ini_set("display_error", 1);
error_reporting(E_ALL & ~(E_WARNING | E_NOTICE));

$old_error_handler = set_error_handler("rgl_error_handler");
$mcrTmStrt = microtime(true);
//Disattiva il caching della pagina
if (headers_sent()) {
	trigger_error(_t("inviati headers prima di checkSession"),E_USER_ERROR);
}
if (!isset($aOpt['no-cache']) or $aOpt['no-cache']) {
	//header("Cache-Control: no-cache, must-revalidate");
	//header("Pragma: no-cache");
}
error_reporting(E_ALL);
// configura il gestore dell'errore definito dall'utente
$oldErrorHandler = set_error_handler("rgl_error_handler");

if (!isset($_REQUEST['xsn'])) {
	rglErr(_t("sessione non identificata (1)"));
	exit();
}

session_start();

$ax = explode('.',$_REQUEST['xsn']);
$subSess = $ax[0];
if (!isset($ax[1])) {
	if (!$isPopUp) {
		rglErr(_t("sessione non identificata (2) - %s",$_REQUEST['xsn']));
		exit();
	}
	$pageSeq = 0;
} else {
	$pageSeq = intval($ax[1]);
}


$userObjKey = RGL_SESS_OBJ_PREF.$subSess;
if(!isset($_SESSION[$userObjKey])){
	rglErr(_t("sessione non identificata (3) - %s",$_REQUEST['xsn']));
	exit();
}
if(!is_object($_SESSION[$userObjKey])){
	rglErr(_t("sessione non identificata (4) - %s",$_REQUEST['xsn']));
	exit();
}
$objSess = $_SESSION[$userObjKey];
if($objSess->login == '@@logout@@'){
	rglErr(_t("eseguito log-out !"));
	exit();
}
$subSess=1;
while(isset($_SESSION[RGL_SESS_OBJ_PREF.$subSess])) {$subSess++;}
$_SESSION[RGL_SESS_OBJ_PREF.$subSess] = clone $_SESSION[$userObjKey];
$objSess = $_SESSION[RGL_SESS_OBJ_PREF.$subSess];
$objSess->uniqid = md5(uniqid(rand(), true));
list($usec, $sec) = explode(" ", microtime());
$tsNow = date('Y-m-d H:i:s',$sec).substr($usec,1,7); 
define('USEROBJ',RGL_SESS_OBJ_PREF.$subSess);
define('SUB_SESS',$subSess);
define('ID_UTENTE', $objSess->idUtente);
define('LOGIN', $objSess->login);
define('XSN',"$subSess.".$objSess->pageSequence);
$objSess->resetHistory();
header("location: ".$objSess->getUrlIniz());
exit();
